<!--
 * @Description: 插槽左右布局左边表右边输入框
 * @author:张捉妖师
-->
<template>
  <div class="staff-manage">
    <!-- 添加删除公用组件使用 -->
    <slot name="zhactbar"></slot>
    <slot name="farmtypeselectslot"></slot>
    <div ref="commonLayout" class="common-layout">
      <!-- 搜索行 -->
      <div class="search-box">
        <slot name="searchbox"></slot>
      </div>
      <!-- 其他内容 -->
      <slot></slot>
      <!-- 主要区域 -->
      <div class="content">
        <!-- 左侧表格区 -->
        <div class="table-box">
          <slot name="tablebox"></slot>
        </div>
        <!-- 右侧列表区 -->
        <div class="form">
          <slot name="form"></slot>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  data() {
    return {
      screenHeight: document.body.clientHeight
    }
  },
  watch: {
    screenHeight(val) {
      // 为了避免频繁触发resize函数导致页面卡顿，使用定时器
      if (!this.timer) {
        // 一旦监听到的screenWidth值改变，就将其重新赋给data里的screenWidth
        this.screenHeight = val
        this.timer = true
        let that = this
        // that.jisuanheight()
        setTimeout(function() {
          // 打印screenWidth变化的值
          that.jisuanheight()
          that.timer = false
        }, 400)
      }
    }
  },
  mounted() {
    const that = this
    window.onresize = () => {
      return (() => {
        // window.screenHeight = document.body.clientHeight
        // that.screenHeight = window.screenHeight
        that.screenHeight = document.body.clientHeight
      })()
    }
    this.jisuanheight()
  },
  methods: {
    jisuanheight() {
      let parent = this.$refs.commonLayout;
      parent.style.setProperty("height", '100%');
      // 获取元素实际需要占据的高度
      let height = parent.scrollHeight - 60
      let zhactbar = this.$slots.zhactbar;
      if (!zhactbar) {
        height = height + 60
      }
      // 判断是否使用农场类型插槽,动态设置高度
      let farmtypenode = this.$slots.farmtypeselectslot;
      if (farmtypenode) {
        parent.style.setProperty("height", height - 50 + 'px');
      } else {
        parent.style.setProperty("height", height + 'px');
      }
    }
  }
}
</script>
<style scoped lang="scss">
@import "~@/styles/variables.scss";
.staff-manage {
  width: 100%;
  height: 100%;
  .common-layout {
    border: 1px solid $borderColor;
    height: calc(100% - #{$actionBarHeight + 60});
    padding: 20px;
    .search-box {
      display: flex;
      align-items: center;
      margin-left: 20px;
      .label-input {
        display: flex;
        align-items: center;
        .label {
          width: 100px;
          white-space: nowrap;
        }
      }
      .search {
        display: flex;
        align-items: center;
        cursor: pointer;
        img {
          height: 30px;
        }
      }
    }
    .content {
      height: calc(100% - 50px);
      margin: 20px 0;
      display: flex;
      .table-box {
        position: relative;
        height: 90%;
        width: 50%;
        overflow-y: auto;
        margin-left: 20px;
        margin-right: 40px;
      }
      .form {
        width: 45%;
        overflow-y: auto;
        display: flex;
        flex-direction:column !important;
        height: 90%;
        border-left: 1px dashed $borderColor;
        padding-left: 30px;
        // ::v-deep .el-form-item {
          // width: 80%;
        // }
        ::v-deep .el-form-item__content {
          display: flex;
          align-items: center;
          text-align: center;
        }
        // ::v-deep .el-form-item__label {
        //   // min-width: 60px;
        // }
        .el-form {
          width: 100%;
          display: flex;
          justify-content: center;
          align-items: center;
          flex-wrap: wrap;
        }
      }
    }
  }
}
</style>
